package com.anjie.powerproject.service.impl;

import com.anjie.powerproject.entity.StationInfo;
import com.anjie.powerproject.repository.StationInfoRepository;
import com.anjie.powerproject.service.StationInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

@Service
public class StationInfoServiceImpl implements StationInfoService {
    @Autowired
    private StationInfoRepository stationInfoRepository;

    @Override
    public boolean checkInfoName(String infoName) {
        List<StationInfo> stationInfos = stationInfoRepository.findStationInfosByStationName(infoName);
        if(stationInfos.size()>0){
            return true;
        } else{
            return false;
        }
    }

    @Override
    public List<StationInfo> findAllInfo() {
        List<StationInfo> stationInfos = stationInfoRepository.findAll();
        return  stationInfos;
    }

    @Override
    public void deleteStationInfoById(Integer id) {
        stationInfoRepository.deleteById(id);
    }

    @Override
    public void saveStationInfo(List list) {
        stationInfoRepository.saveAll(list);
    }

    @Override
    public void deleteStationInfoByStationName(String stationName) {
        stationInfoRepository.deleteStationInfoByStationName(stationName);
    }

    @Override
    public StationInfo findStationInfoById(Integer id) {

        StationInfo stationInfo = new StationInfo();
        stationInfo = stationInfoRepository.findStationInfoById(id);
        return  stationInfo;
    }

    @Override
    public void updateStationInfo(StationInfo stationInfo) {
//        stationInfoRepository.updateStationInfo(stationInfo.getStationName(),stationInfo.getStationArea(),stationInfo.getBuildingArea(),stationInfo.getConstructionYear(),stationInfo.getStationAdress(),stationInfo.getCityCode(),stationInfo.getBatteryCode(),stationInfo.getBatteryPointId(),stationInfo.getEnergyCode(),stationInfo.getEnergyPointId(),stationInfo.getTemperatureCode(),stationInfo.getTemperaturePointId(),stationInfo.getId());
        stationInfoRepository.updateStationInfo(stationInfo.getStationName(),stationInfo.getStationArea(),stationInfo.getBuildingArea(),stationInfo.getConstructionYear(),stationInfo.getStationAdress(),stationInfo.getCityCode(),stationInfo.getBatteryCode(),stationInfo.getBatteryPointId(),stationInfo.getEnergyCode(),stationInfo.getEnergyPointId(),stationInfo.getId());
    }


    @Override
    public StationInfo findStationInfoLimitFirst() {
        return stationInfoRepository.findStationInfoLimitFirst();
    }
}
